package control

import entity.*

class OrderControl {
    
    WoodCatalog catalog
    
    def totalPrice(Order order) {
        if (order && order.woods) {
            def total = 0.0
            def id, quantity
            order.woods.each {id = it.key
                        quantity = it.value
                        total += quantity*catalog.bfPrices.get(id)}
            total
        }else{
            "This order is empty."
        }
    }
    
    def multiplier(value) {
        if (value in 1..100)
            1.0
        else
        if (value in 101..200)
            2.0
        else
        if (value in 201..300)
            3.0
        else
        if (value in 301..400)
            4.0
        else
        if (value in 401..500)
            5.0
        else
        if (value in 501..1000)
            5.5
    }
    
    def totalDeliveryTime(Order order) {
        if (order && order.woods) {
            def id, quantity
            (order.woods.collect{id = it.key
                                 quantity = it.value
                                 multiplier(quantity)*catalog.deliveryTimes.get(id)}).max()
        }else{
            "This order is empty."
        }
    }
    
    def validateClientName(String name) {
        
        if (${name.length()} >= 5 && ${name.length()}<=30){
            true
        }
            false
    }
    
     def validateDeliveryAddress(String address) {
        
        if (${address.length()} >= 10 && ${address.length()}<=30){
            true
        }
            false
    }
	
}

